package me.goldze.mvvmhabit.utils;

import android.content.Context;
import android.graphics.Color;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;

import me.goldze.mvvmhabit.R;
import me.goldze.mvvmhabit.utils.GlideCircleTransform;

public class GlideUtlis {

    //普通设置
    public static void glideCommon(Context context, String path, ImageView imageView, int bg) {
        try {
            Glide.with(context).load(path)
                    .apply(new RequestOptions()
                            .placeholder(bg).error(bg).centerCrop().diskCacheStrategy(DiskCacheStrategy.ALL).dontTransform())
                    .into(imageView);
        } catch (Exception e) {
            e.getMessage();
        }
    }

    //普通设置
    public static void glideDrawableImage(Context context, Integer path, ImageView imageView, int bg) {
        try {
            Glide.with(context).load(path)
                    .apply(new RequestOptions()
                            .placeholder(bg).error(bg).centerCrop().diskCacheStrategy(DiskCacheStrategy.ALL).dontTransform())
                    .into(imageView);
        } catch (Exception e) {
            e.getMessage();
        }
    }


    //普通设置
    public static void glideCommonRec(Context context, String path, ImageView imageView, int bg) {
        try {
            Glide.with(context).load(path)
                    .apply(new RequestOptions()
                            .placeholder(bg).error(bg).centerCrop().diskCacheStrategy(DiskCacheStrategy.ALL).dontTransform())
                    .into(imageView);
        } catch (Exception e) {
            e.getMessage();
        }
    }



    //不适用缓存设置头像
    public static void glideNoCache(Context context, String path, ImageView imageView) {
        try {
            Glide.with(context).load(path)
                    .apply(new RequestOptions()
                            .skipMemoryCache(true) // 不使用内存缓存
                            .diskCacheStrategy(DiskCacheStrategy.NONE) // 不使用磁盘缓存
                            .placeholder(R.drawable.mei).centerCrop()
                            .transform(new GlideCircleTransform(context, 1, Color.parseColor("#dddddd"))))
                    .into(imageView);
        } catch (Exception e) {
            e.getMessage();
        }

    }

    //不适用缓存设置图片
    public static void glideImageView(Context context, String path, ImageView imageView) {
        try {
            Glide.with(context).load(path)
                    .apply(new RequestOptions()
                            .skipMemoryCache(true) // 不使用内存缓存
                            .diskCacheStrategy(DiskCacheStrategy.NONE) // 不使用磁盘缓存
                            .placeholder(R.mipmap.imgz).centerCrop())
                    .into(imageView);
        } catch (Exception e) {
            e.getMessage();
        }

    }


    //设置头像
    public static void glideUserHead(Context context, String path, ImageView imageView) {
        try {
            Glide.with(context).load(path)
                    .apply(new RequestOptions()
                            .placeholder(R.drawable.mei).centerCrop()
                            .transform(new GlideCircleTransform(context, 1, Color.parseColor("#dddddd"))).diskCacheStrategy(DiskCacheStrategy.ALL))
                    .into(imageView);
        } catch (Exception e) {
            e.getMessage();
        }

    }

    public static void glideImageView(Context context, Integer path, ImageView imageView, int bg) {

        try {
            Glide.with(context).load(path)
                    .apply(new RequestOptions()
                            .placeholder(bg).error(bg).centerCrop()
                            .diskCacheStrategy(DiskCacheStrategy.ALL))
                    .into(imageView);
        } catch (Exception e) {
            e.getMessage();
        }

    }


    public static void glideRadius(Context context, String path, ImageView imageView, int range) {
        Glide.with(context)
                .load(path)
                .apply(RequestOptions.placeholderOf(R.mipmap.mo)
                        .error(R.mipmap.mo).diskCacheStrategy(DiskCacheStrategy.ALL)
                        .bitmapTransform(new GlideRoundTransform(context,range))).into(imageView);


    }


}
